﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "Towards", menuName = "BulletMotion/Towards")]
public class Towards : BulletMotion
{
    [Tooltip("要转过的角度。正为逆时针，负为顺时针")]
    public float angle;

    public Towards(float awake, float life, float ang)
    {
        awakeTime = awake;
        lifeTime = life;
        angle = ang;
    }

    public override void Awaking(float t)
    {
        base.Awaking(t);
        lifeTime = awakeTime + 1;
    }

    public override Vector2 Motion(float t)
    {
        if (awake)
        {
            float rad = angle * Mathf.PI / 180;
            float x = Mathf.Cos(rad);
            float y = Mathf.Sin(rad);
            motionController.towards = new Vector2(Vector2.Dot(motionController.towards, new Vector2(x, -y)), Vector2.Dot(motionController.towards, new Vector2(y, x)));
            lifeTime = 0;
        }
        return Vector2.zero;
    }
}
